package com.mrzhou.core.tool.utils;

import com.mrzhou.core.enums.BaseCodeEnum;

import java.util.Arrays;

/**
 * 枚举工具类
 * @author qiang.zhou
 */
public class EnumUtil {

    /**
     * 根据code获取枚举类
     * @param code
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T extends BaseCodeEnum> T getEnumByCode(Object code, Class<T> clazz) {
        if (null == code) {
            return null;
        }
        return Arrays.stream(clazz.getEnumConstants())
                .filter(var -> code.equals(var.code()))
                .findFirst()
                .orElse(null);
    }


}
